package com.smartpro.mis.modular.system.dao;

import com.smartpro.mis.modular.business.neo4jEntity.N4jDistributor;
import com.smartpro.mis.modular.business.neo4jEntity.N4jUser;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.Collection;

/**
 * @author Michael Hunger
 * @author Mark Angrish
 * @author Michael J. Simons
 */
@RepositoryRestResource(collectionResourceRel = "n4jDistributor", path = "n4jDistributor")
public interface N4jDistributorRepository extends Neo4jRepository<N4jDistributor, Long> {

	N4jDistributor findByDistributorID(@Param("distributorID") int distributorID);

	/**
	 * 获取某个推广员的下线推广员
	 * @param distributorID
	 * @return
	 */
    @Query("MATCH (m:N4jDistributor)-[r:DISTRIBUTE_EXPIRY_DATE]- >(a:N4jDistributor) where m.distributorID={distributorID} RETURN m,r,a")
	Collection<N4jDistributor> getBackDistributors(@Param("distributorID") int distributorID);
}